<template>
  <div v-loading.lock="loading" class="base-content">
    <div class="basic-info">
      <el-form ref="queryForm" :inline="true" :model="queryForm">
        <!-- <el-form-item>
            <el-button type="primary" @click="onQuery">查询</el-button>
            <el-button @click="cancelForm">清空</el-button>
        </el-form-item>-->
      </el-form>

      <div class="base-content-operate">
        <el-button
          v-rights="'Add'"
          icon="el-icon-plus"
          type="primary"
          @click="onNew"
          >新增</el-button
        >
      </div>

      <el-table
        :data="list"
        element-loading-text="Loading"
        fit
        highlight-current-row
      >
        <el-table-column align="center" label="序号" width="50">
          <template v-slot="scope">{{ scope.$index + 1 }}</template>
        </el-table-column>
        <el-table-column label="名称">
          <template v-slot="scope">{{ scope.row.appName }}</template>
        </el-table-column>
        <el-table-column label="版本">
          <template v-slot="scope">{{ scope.row.versionCode }}</template>
        </el-table-column>
        <el-table-column label="大小">
          <template v-slot="scope">{{ scope.row.fileSize }}</template>
        </el-table-column>

        <el-table-column label="操作">
          <template v-slot="scope">
            <div class="base-table-operation">
              <el-link
                size="mini"
                type="primary"
                @click="handleEdit(scope.row, true)"
                >查看</el-link
              >
              <el-link size="mini" type="primary" @click="handleEdit(scope.row)"
                >编辑</el-link
              >
              <el-link
                size="mini"
                type="danger"
                @click="handleDelete(scope.row)"
                >删除</el-link
              >
            </div>
          </template>
        </el-table-column>
      </el-table>

      <BasePagination
        :total="pagination.total"
        :current-page="pagination.pageIndex"
        :page-count="pagination.total"
        @changePage="changePage"
        @sizeChange="sizeChange"
      />
    </div>

    <ElnAppVersionEdit
      v-if="isShowDialog"
      ref="ElnAppVersionEdit"
      v-model="isShowDialog"
      :edit-id="editId"
      :readonly="readonly"
      @success="getList"
    />
  </div>
</template>

<script>
import { deleteVersion, getList } from "../../../api/Eln/ElnAppVersion.js";
import ElnAppVersionEdit from "./ElnAppVersionEdit.vue";
export default {
  name: "ElnAppVersionList",
  components: { ElnAppVersionEdit },
  data() {
    return {
      loading: true,
      list: [],
      queryForm: {},
      dialogFormVisible: false,
      pagination: {
        pageIndex: 1,
        pageSize: 10,
        total: 0,
      },
      editId: "",
      readonly: false,
      isShowDialog: false,
    };
  },
  created() {
    this.getList();
  },
  methods: {
    changePage(val) {
      this.pagination.pageIndex = val;
      this.getList();
    },
    sizeChange(val) {
      this.pagination.pageIndex = 1;
      this.pagination.pageSize = val;
      this.getList();
    },
    cancelForm() {
      this.$refs.queryForm.resetFields();
      this.pagination.pageIndex = 1;
      this.getList();
    },
    getList() {
      this.loading = true;
      getList(this.queryForm, this.pagination)
        .then((res) => {
          this.list = res.data.dataList ? res.data.dataList : [];
          this.pagination.total = res.data.total;
          this.loading = false;
        })
        .catch(() => {
          this.loading = false;
        });
    },
    onNew() {
      this.readonly = false;
      this.editId = "";
      this.isShowDialog = true;
    },
    handleDelete(rowData) {
      this.Helper.deleteConfirm(() => {
        this.loading = true;
        deleteVersion({ id: rowData.id })
          .then((res) => {
            this.getList();
            this.loading = false;
          })
          .catch(() => {
            this.loading = false;
          });
      });
    },
    handleEdit(rowData, readonly) {
      this.readonly = !!readonly;
      this.editId = rowData.id;
      this.isShowDialog = true;
    },
    onQuery() {
      this.pagination.pageIndex = 1;
      this.getList();
    },
  },
};
</script>
